package com.ruoyi.cms.fileInfo.controller;

import com.ruoyi.cms.fileInfo.domain.FileClassAssign;
import com.ruoyi.cms.fileInfo.domain.SysFileInfo;
import com.ruoyi.cms.fileInfo.service.FileClassAssignInterface;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * RestController 注解仅有一个继承自 @Controller 的 value 属性，
 * 用于指定控制器在 Spring 容器中的 Bean 名称，不直接参与请求路径的定义。
 * 请求路径需通过 @RequestMapping 及其派生注解（@GetMapping 等）配置
 * */
@RestController
@RequestMapping("/claasAssign")
@AllArgsConstructor
public class FileClassAssignController extends BaseController {

    private final FileClassAssignInterface fileClassAssignService;

    @GetMapping("/list")
    public TableDataInfo list(FileClassAssign fileClassAssign) {
        startPage();
        List<FileClassAssign> list = fileClassAssignService.selectFileClassAssignList(fileClassAssign);
        return getDataTable(list);
    }

    @GetMapping("/listAssign")
    public TableDataInfo listAssign(FileClassAssign fileClassAssign) {
        startPage();
        List<FileClassAssign> list = fileClassAssignService.selectFileClassAssignStudentList(fileClassAssign);
        return getDataTable(list);
    }

    @GetMapping("/id/{id}")
    public AjaxResult getInfo(@PathVariable long id) {
        FileClassAssign fileClassAssign = fileClassAssignService.selectFileClassAssignById(id);
        return AjaxResult.success(fileClassAssign);
    }

    @PutMapping("/assign/{student}/{id}")
    public AjaxResult assign(@PathVariable Integer student, @PathVariable Long id) {
        int updated = fileClassAssignService.updateFileClassAssign(student, id);
        return AjaxResult.success(updated);
    }

    @PutMapping("/assignNot/{id}")
    public AjaxResult assignNot(@PathVariable Long id) {
        int updated = fileClassAssignService.updateFileClassAssignNot(id);
        return AjaxResult.success(updated);
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody FileClassAssign fileClassAssign) {
        int inserted = fileClassAssignService.insertFileClassAssign(fileClassAssign);
        return AjaxResult.success(inserted);
    }

    @PostMapping("/addData")
    public AjaxResult addData(@RequestBody SysFileInfo sysFileInfo) {
        int inserted = fileClassAssignService.insertFileClassAssign(sysFileInfo);
        return AjaxResult.success(inserted);
    }
}
